﻿using M.WWHours.API.Command.WorkerListCommand;
using M.WWHours.Domain.Model;
using M.WWHours.Repository.WWHoursInterface;
using MediatR;

namespace M.WWHours.API.CommandHandlers.WorkerListCommandHandler
{
    /// <summary>
    /// 更新工人列表命令处理器
    /// </summary>
    public class UpdateWorkerListCommandHandler : IRequestHandler<UpdateWorkerListCommand, int>
    {
        /// <summary>
        /// 工人列表仓储接口
        /// </summary>
        protected readonly IWorkerListRepository workerListRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="workerListRepository">工人列表仓储接口</param>
        public UpdateWorkerListCommandHandler(IWorkerListRepository workerListRepository)
        {
            this.workerListRepository = workerListRepository;
        }

        /// <summary>
        /// 更新工人列表命令处理器
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(UpdateWorkerListCommand request, CancellationToken cancellationToken)
        {
            return await workerListRepository.UpdateAsync(new WorkerList()
            {
                WorkerListId = request.WorkerListId,
                WorkerNumber = request.WorkerNumber,
                WorkersName = request.WorkersName,
                PhoneNumber = request.PhoneNumber,
                Gender = request.Gender,
                Department = request.Department,
                TeamsAndGroups = request.TeamsAndGroups,
                Status = request.Status,
                CreatedBy = request.CreatedBy,
                CreatedDate = request.CreatedDate,
                UpdatedBy = request.UpdatedBy,
                UpdatedDate = DateTime.Now,
                DeletedBy = request.DeletedBy,
                DeletedDate = request.DeletedDate,
                IsDeleted = request.IsDeleted
            });
        }
    }
}
